package com.hs.sharding.controller;

import com.hs.sharding.service.UserService;
import com.hs.sharding.req.UserReq;
import com.hs.sharding.entity.R;
import com.hs.sharding.entity.User;
import com.hs.sharding.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @Description: TODO
 * @Author 胡尚
 * @Date: 2024/8/2 10:12
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping
    public R addUser(@RequestBody UserReq req){
        int i = userService.addUser(req);
        return R.ok();
    }

    @GetMapping
    public R queryUser(@RequestParam("userId")
                           @NotNull(message = "userId不能为null") Long userId){
        User user = userService.getById(userId);
        return R.ok(user);

    }
}
